using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LoadSceneManager : MonoBehaviour
{
    public static LoadSceneManager Instance;

    private void Awake()
    {
        Instance = this;
        DontDestroyOnLoad(gameObject);
    }


    public void LoadScene(string sceneName)
    {
        Debug.Log(sceneName);
        StartCoroutine(LoadSceneCo(sceneName));
    }

    private IEnumerator LoadSceneCo(string sceneName)
    {
        UI_SceneFade sceneLoadUI = UI_SceneFade.Instance;
        sceneLoadUI.DoFadeIn(.5f);

        yield return new WaitUntil(() => sceneLoadUI.IsFadeFinish);

        SceneManager.LoadScene(sceneName);

        yield return new WaitForSeconds(.2f);

        sceneLoadUI = UI_SceneFade.Instance;

        sceneLoadUI.DoFadeOut(.5f);
    }
}
